package org.xx.armory.spring5.mvc;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

import static org.apache.commons.text.StringEscapeUtils.escapeEcmaScript;

/**
 * 请求参数不合法导致的异常。
 */
@ResponseStatus(HttpStatus.BAD_REQUEST)
public class IllegalRequestParamException
        extends RuntimeException {
    private static final long serialVersionUID = 1L;

    public IllegalRequestParamException(
            String name
    ) {
        this(name, null);
    }

    public IllegalRequestParamException(
            String name,
            String detail
    ) {
        super("Illegal request param \"" + escapeEcmaScript(name) + "\""
                      + ((detail != null && !detail.isBlank()) ? ", " + detail : ""));
    }
}
